package com.kmust.dream.wanderingdream.product.controller;

import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.product.entity.ProductPropertyName;
import com.kmust.dream.wanderingdream.product.service.ProductPropertyNameService;
import com.kmust.dream.wanderingdream.product.service.ProductPropertyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/product/propertyName")
@Api(value = "商品属性名API")
public class ProductPropertyNameController {
    @Autowired
    ProductPropertyNameService productPropertyNameService;
    @Autowired
    ProductPropertyService productPropertyService;

    /**
     * 获取所有的属性名称
     *
     * @return resultBean
     */
    @ApiOperation(value = "获取所有的属性名称", notes = "无参数")
    @GetMapping("/getAllPropertyNames")
    public ResultBean getAllPropertyNames() {
        return productPropertyNameService.getAllPropertyNames();
    }

    /**
     * 根据主键获取属性名称对象
     *
     * @param NameId 主键
     * @return resultBean
     */
    @ApiOperation(value = "根据主键获取属性名称对象", notes = "参数是nameId")
    @GetMapping("/getPropertyNameByNameId/{NameId}")
    public ResultBean getPropertyNameByPropertyNameId(@PathVariable Integer NameId) {
        return productPropertyNameService.getPropertyNameByPropertyNameId(NameId);
    }

    /**
     * 根据分类id获取属性名称对象
     *
     * @param categoryId 种类id
     * @return resultBean
     */
    @ApiOperation(value = "根据分类id获取属性名称对象", notes = "参数是categoryId")
    @GetMapping("/getPropertyNameByCategoryId/{categoryId}")
    public ResultBean getPropertyName(@PathVariable Integer categoryId) {
        return productPropertyNameService.getPropertyNameByCategoryId(categoryId);
    }

    /**
     * 添加属性名称对象
     *
     * @param productPropertyName 属性名称对象
     * @return resultBean
     */
    @ApiOperation(value = "添加属性名称对象", notes = "参数是属性名称对象json")
    @PostMapping("/addPropertyName")
    public ResultBean addPropertyName(@RequestBody ProductPropertyName productPropertyName) {
        return productPropertyNameService.addProductPropertyName(productPropertyName);
    }

    /**
     * 更新属性名称对象
     *
     * @param productPropertyName 属性名称对象
     * @return resultBean
     */
    @ApiOperation(value = "更新属性名称对象", notes = "参数是属性名称对象json")
    @PutMapping("/updatePropertyName")
    public ResultBean updatePropertyName(@RequestBody ProductPropertyName productPropertyName) {
        return productPropertyNameService.updateProductPropertyName(productPropertyName);
    }

    /**
     * 删除属性名称对象
     *
     * @param NameId 属性名称id
     * @return resultBean
     */
    @ApiOperation(value = "删除属性名称对象", notes = "参数是主键")
    @DeleteMapping("/deletePropertyName/{NameId}")
    public ResultBean deletePropertyName(@PathVariable Integer NameId) {
        return productPropertyNameService.deleteProductPropertyName(NameId);
    }


    /**
     * 根据商品种类主键获取对应值
     * @param productCategoryId 商品种类主键
     * @return resultBean
     */
    @ApiOperation("根据商品主键获取对应值")
    @GetMapping("/getCategoryNamesByproductCategoryId/{productCategoryId}")
    public ResultBean getCategoryNamesByProductId(@PathVariable Integer productCategoryId) {
        return productPropertyNameService.getPropertyNameByProductId(productCategoryId);
    }
}
